package org.shj.book2.chapter05;

/**
 * Producer - Consumer 模式。 感觉跟 chapter3 中的模式没什么区别
 * 本例中的 Table 是 Producer 和 Consumer 之间的 Channel， 改变 Table，可以实现 FIFO 或者 FILO .
 * 
 * @author huangjian
 *
 */
public class Main {

	public static void main(String[] args){
		Table table = new Table(3);
		MakerThread maker1 = new MakerThread("MakerThread-1", table, 31415);
		MakerThread maker2 = new MakerThread("MakerThread-2", table, 92635);
		MakerThread maker3 = new MakerThread("MakerThread-3", table, 58979);
		
		EaterThread eater1 = new EaterThread("EaterThread-1", table, 32384);
		EaterThread eater2 = new EaterThread("EaterThread-2", table, 62643);
		EaterThread eater3 = new EaterThread("EaterThread-3", table, 38327);
		
		maker1.start();
		maker2.start();
		maker3.start();
		
		eater1.start();
		eater2.start();
		eater3.start();
		
		long begin = System.currentTimeMillis();
		
		//运行10秒左右，中断各个线程
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			
			e.printStackTrace();
		}
	
		maker1.interrupt();
		maker2.interrupt();
		maker3.interrupt();
		eater1.interrupt();
		eater2.interrupt();
		eater3.interrupt();
		
		System.out.println(System.currentTimeMillis() - begin);
	}
}
